﻿using MediatR;
using Microsoft.EntityFrameworkCore;
using SlaughterItem.Common.Domains.Check_Ins;
using SlaughterItem.Common.Dtos;
using SlaughterItem.Common.Infrastructures.Interfaces;
using SlaughterItem.Enum;

namespace GetSlaughterItem.API.Application.Commands.Week02.Check_In
{
    //绑定下拉
    public class CheckInShow2Handler : IRequestHandler<CheckInShow2Command, Result>
    {
        IBaseRepositoryGet<CheckIn> CheckInRep;

        public CheckInShow2Handler(IBaseRepositoryGet<CheckIn> CheckInRep)
        {
            this.CheckInRep = CheckInRep;
        }

        public async Task<Result> Handle(CheckInShow2Command request, CancellationToken cancellationToken)
        {
            var result = new Result() { Code = (int)CommonErrorCode.Search };
            try
            {
                var list = await CheckInRep.GetAll().ToListAsync();
                if (list != null)
                {
                    result.Code = (int)CommonErrorCode.Success;
                    result.Data = list;
                    result.Msg = "成功";
                }
            }
            catch (Exception)
            {

                throw;
            }
            return result;
        }
    }
}
